package com.xuj.recyclerviewdemo.custom;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xuj.recyclerviewdemo.R;

import java.util.List;


/**
 * Created by wenld- on 2015/9/23.
 */
public class ImageListAdapter extends AdvancedAdapter<ImageListAdapter.ViewHolder, String> {
    private Context mContext;

    public ImageListAdapter(Context mContext, List<String> mData, ItemClickInterface listener) {
        this.mContext = mContext;
        this.mData = mData;
        this.listener = listener;
    }

    @Override
    public int getAdvanceViewType(int position) {
        return position;
    }

    @Override
    public void onBindAdvanceViewHolder(ViewHolder holder, int i) {
        String data = getItem(i);
        if (data != null) {
            holder.mTextView.setText(data);
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateAdvanceViewHolder(ViewGroup parent, int viewType) {
        ViewHolder vh = new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item, parent, false));
        return vh;
    }

    public class ViewHolder extends AdvancedAdapter.ViewHolder {
        public TextView mTextView;

        public ViewHolder(View v) {
            super(v);
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (listener != null) {
                        listener.onItemClick(mData.get(getAdpPosition()), getAdpPosition());
                    }
                }
            });
            mTextView = (TextView) v.findViewById(R.id.textView);
        }
    }
}
